package com.lp.biz.category.controller;

import com.lp.biz.category.model.vo.LabelCreate;
import com.lp.biz.category.service.LabelService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.*;

/**
 * @program: backend
 * @description:
 * @author: Ke.Song
 * @since: 2024-06-01 11:41:13
 */
@RestController
@RequestMapping("/labels")
public class LabelController {

    @Autowired
    private LabelService labelService;

    /**
     * 创建标签
     * @param params 创建参数
     * @return 处理结果
     */
    @PostMapping("")
    @PermissionAnnotation(menus = {CONTENT_READING, CONTENT_STORY, CONTENT_FAMOUS_REM})
    public CommonResult addLabel(@RequestBody @Validated LabelCreate params) {
        labelService.addLabel(params);
        return CommonResult.success();
    }

    /**
     * 获取标签下拉菜单
     * @param categoryCode 类型code
     * @param name label
     * @return 查询结果
     */
    @GetMapping("")
    @PermissionAnnotation(menus = {CONTENT_READING, CONTENT_STORY, CONTENT_FAMOUS_REM})
    public CommonResult getLabels(@RequestParam String categoryCode, @RequestParam(required = false) String name) {
        return labelService.getLabels(categoryCode, name);
    }

    /**
     * 更新标签
     * @param labelId 标签id
     * @param params 标签名
     * @return 处理结果
     */
    @PutMapping("/{labelId}")
    @PermissionAnnotation(menus = {CONTENT_READING, CONTENT_STORY, CONTENT_FAMOUS_REM})
    public CommonResult updateLabel(@PathVariable Integer labelId, @RequestBody @Validated LabelCreate params) {
        labelService.updateLabel(labelId, params);
        return CommonResult.success();
    }

    /**
     * 删除标签
     * @param labelId 标签id
     * @return 处理结果
     */
    @DeleteMapping("/{labelId}")
    @PermissionAnnotation(menus = {CONTENT_READING, CONTENT_STORY, CONTENT_FAMOUS_REM})
    public CommonResult deleteLabel(@PathVariable Integer labelId) {
        labelService.deleteLabel(labelId);
        return CommonResult.success();
    }
}
